package com.example.bms.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.bms.entity.JudgeQuestion;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;


/**
 * @apiNote 增加和查询判断题试题
 * @author 扶纪权
 * @email 1605009600@qq.com
 * @since 1.0.0
 */
@Mapper
public interface JudgeQuestionMapper {


    /**
     * @apiNote 查询判断题题库
     * @author 扶纪权
     * @param paperId 试卷Id
     * @email 1605009600@qq.com
     * @return List<JudgeQuestion>
     * @since 1.0.0
     */
    @Select("select * from judge_question where questionId in (select questionId from paper_manage where questionType = 3 and paperId = #{paperId})")
    List<JudgeQuestion> findByIdAndType(Integer paperId);


    /**
     * @apiNote 查询判断题题库
     * @author 扶纪权
     * @param page 页码
     * @email 1605009600@qq.com
     * @return IPage<JudgeQuestion>
     * @since 1.0.0
     */
    @Select("select * from judge_question")
    IPage<JudgeQuestion> findAll(Page page);


    /**
     * @apiNote 查询最后一条记录的questionId
     * @author 扶纪权
     * @email 1605009600@qq.com
     * @return JudgeQuestion
     * @since 1.0.0
     */
    @Select("select questionId from judge_question order by questionId desc limit 1")
    JudgeQuestion findOnlyQuestionId();


    /**
     * @apiNote 插入一个判断题
     * @author 扶纪权
     * @param judgeQuestion 判断题实体对象
     * - subject 科目
     * - question 题目
     * - answer 答案(T或F）
     * - analysis 分析
     * - level 难度
     * - section 模块     * @email 1605009600@qq.com
     * @return int类型，插入成功返回1，插入失败返回0
     * @since 1.0.0
     */
    @Insert("insert into judge_question(subject,question,answer,analysis,level,section) values " +
            "(#{subject},#{question},#{answer},#{analysis},#{level},#{section})")
    int add(JudgeQuestion judgeQuestion);


    /**
     * @apiNote 查询questionId
     * @author 扶纪权
     * @param subject 科目
     * @param pageNo  页码
     * - questionId 问题id
     * @email 1605009600@qq.com
     * @return List<Integer>
     * @since 1.0.0
     */
    @Select("select questionId from judge_question  where subject=#{subject}  order by rand() desc limit #{pageNo}")
    List<Integer> findBySubject(String subject,Integer pageNo);
}
